package com.wenli.graduate2022.wenliGreenShop.controller;

import com.wenli.graduate2022.wenliGreenShop.entity.Admin;
import com.wenli.graduate2022.wenliGreenShop.service.servDao.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author HuangHai
 * @date 2021/10/5 14:02
 */
@RestController
public class AdminController { //后台可以利用GET、POST、PUT、DELETE这四种方式实现Restful风格的查、增、改、删（一一对应)
    @Autowired
    AdminService adminService;

    @PostMapping("adminLogin")
    public Admin adminLogin(@RequestParam("userName") String name, @RequestParam("userPassword") String psd){
        Admin admin = adminService.adminLogin(name, psd);
        System.out.println(admin);
        if (admin != null){
            return admin;
        }
        return null;
    }

    @GetMapping("admin/{id}")
    public Admin findById(@PathVariable("id") Integer id){
        return adminService.findById(id);
    }

    @PutMapping("admin/{id}/{password}")
    public int updatePassword(@RequestBody Admin admin,@PathVariable("id") Integer id, @PathVariable("password") String password){
        return adminService.updatePassword(admin,id,password);
    }
}
